We introduce the PyMatting package for Python which implements various methods to solve the alpha matting problem.
Given an input image and a hand-drawn trimap (top row), alpha matting estimates the alpha channel of a foreground object which can then be composed onto a different background (bottom row).
PyMatting provides:- Alpha matting implementations for: - Closed Form Alpha Matting  - Large Kernel Matting  - KNN Matting  - Learning Based Digital Matting  - Random Walk Matting - Foreground estimation implementations for: - Closed Form Foreground Estimation  - Multilevel Foreground Estimation (CPU, CUDA and OpenCL)- Fast multithreaded KNN search- Preconditioners to accelerate the convergence rate of conjugate gradient descent: - The incomplete thresholded Cholesky decomposition (Incomplete is part of the name. The implementation is quite complete.) - The V-Cycle Geometric Multigrid preconditioner- Readable code leveraging NumPy, SciPy and Numba
Minimal requiremens* numpy>=1.16.0* pillow>=5.2.0* numba>=0.47.0* scipy>=1.1.0
Additional requirements for GPU support* cupy-cuda90>=6.5.0 or similar* pyopencl>=2019.1.2
Requirements to run the tests* pytest>=5.3.4
bashpip3 install pymatting
bashgit clone https://github.com/pymatting/pymattingcd pymattingpip3 install .
```pythonfrom pymatting import cutout
cutout( # input image path "data/lemur.png", # input trimap path "data/lemurtrimap.png", # output cutout path "lemurcutout.png")```
Run the tests from the main directory:
python3 tests/download_images.py pip3 install -r requirements_tests.txt pytest
Currently 89% of the code is covered by tests.
See also the list of contributors who participated in this project.
This project is licensed under the MIT License - see the LICENSE.md file for details
 Anat Levin, Dani Lischinski, and Yair Weiss. A closed-form solution to natural image matting. IEEE transactions on pattern analysis and machine intelligence, 30(2):228–242, 2007.
Kaiming He, Jian Sun, and Xiaoou Tang. Fast matting using large kernel matting laplacian matrices. In 2010 IEEE Computer Society Conference on Computer Vision and Pattern Recognition, 2165–2172. IEEE, 2010.
Qifeng Chen, Dingzeyu Li, and Chi-Keung Tang. Knn matting. IEEE transactions on pattern analysis and machine intelligence, 35(9):2175–2188, 2013.
Yuanjie Zheng and Chandra Kambhamettu. Learning based digital matting. In 2009 IEEE 12th international conference on computer vision, 889–896. IEEE, 2009.
Leo Grady, Thomas Schiwietz, Shmuel Aharon, and Rüdiger Westermann. Random walks for interactive alpha-matting. In Proceedings of VIIP, volume 2005, 423–429. 2005.
git clone pymatting-pymatting_-_2020-02-14_06-29-45.bundle